package com.github.icloudpay.pay.core.rest;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.icloudpay.pay.core.biz.PayChannelInterfaceBiz;
import com.github.icloudpay.pay.core.entity.PayChannelInterface;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequestMapping("admin/payChannelInterface")
public class PayChannelInterfaceController {
	
	@Autowired
	private PayChannelInterfaceBiz biz;

	
	/**
	 * 修改支付通道接口
	 * @param params
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public ObjectRestResponse<PayChannelInterface> updatePayChannelInterface(@RequestBody Map<String, Object> params) {
		log.info("更新支付通道接口，请求参数。。。{}"+params);
		String payChannelNo = (String) params.get("payChannelNo");
		String payServiceName = (String) params.get("payServiceName");
		String payQueryServiceName = (String) params.get("payQueryServiceName");
		String refundServiceName = (String) params.get("refundServiceName");
		String refundQueryServiceName = (String) params.get("refundQueryServiceName");
		String payforanotherServiceName = (String) params.get("payforanotherServiceName");
		String payforanotherQueryServiceName = (String) params.get("payforanotherQueryServiceName");
		PayChannelInterface channelInterface = new PayChannelInterface();
		channelInterface.setPayChannelNo(payChannelNo);
		channelInterface.setPayServiceName(payServiceName);
		channelInterface.setPayQueryServiceName(payQueryServiceName);
		channelInterface.setRefundServiceName(refundServiceName);
		channelInterface.setRefundQueryServiceName(refundQueryServiceName);
		channelInterface.setPayforanotherQueryServiceName(payforanotherQueryServiceName);
		channelInterface.setPayforanotherServiceName(payforanotherServiceName);
		biz.updateById(channelInterface);
		return new ObjectRestResponse<PayChannelInterface>();
	}
	
	
	/**
	 * 支付通道接口详情
	 * @param params
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/info", method = RequestMethod.POST)
	public ObjectRestResponse<PayChannelInterface> queryPayChannelInterfaceInfo(@RequestBody Map<String, Object> params) {
		log.info("查询支付通道接口，请求参数.。。。{}"+params);
		ObjectRestResponse<PayChannelInterface> response = new ObjectRestResponse<>();
		PayChannelInterface config = biz.selectById(params.get("payChannelNo"));
		response.data(config);
		log.info("查询支付通道配置，响应参数.。。。{}"+response);
		return response;
	}
}
